package cn.edu.hnu.homework.api.Mapper;

import cn.edu.hnu.homework.api.Bean.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("SELECT * FROM user")
    List<User> getAll();

    @Select("select * from user where username = #{username}")
    List<User> getByUsername(String username);

    // two and more params user 1 2... or it will occur error like Parameter 'username' not found. Available parameters are [arg1, arg0, param1, param2]
    @Select("select * from user where username = #{param1} and password = #{param2}")
    List<User> getByUsernameAndPassword(String username, String password);

    @Insert("INSERT INTO `user`(`username`, `password`) VALUES (#{param1}, #{param2});")
    void insert(String username, String password);

    @Update("UPDATE `user` SET `password` = #{password} WHERE `username` = #{username};")
    void update(String username, String password);

    @Delete("delete from user where username = #{username}")
    void delete(String username);

}
